<script setup lang="ts">
import {Coin, Film, Ticket, User, UserFilled} from "@element-plus/icons-vue";
import CountCard from "@/components/card/CountCard.vue";
import {onMounted,ref} from "vue";
import {useGetIndexDataApi} from "@/services/api";
import type {IndexData} from "@/interface";
import LineCharts from "@/components/charts/line-charts.vue";
import type {LineChartsProps} from "@/interface/line-charts.ts";


const indexData = ref<IndexData>({
  charts: [],
  movieCount: 0,
  orderCount: 0,
  salesVolume: "",
  userCount: 0
})
const chartsProps = ref<LineChartsProps>({
  dataList: [],
  timeList: []
})
const init = async () =>{
  const {data:res} = await useGetIndexDataApi()
  indexData.value = res
  indexData.value.charts.forEach(value => {
    chartsProps.value.dataList.push(parseFloat(value.amount))
    chartsProps.value.timeList.push(value.orderTime)
  })
}
onMounted(()=>{
  init()
})
</script>

<template>
  <div class="content">
    <div class="space">
      <el-space :size="0" style="padding-bottom: 20px" class="card-space">
        <div>
          <count-card title="在售电影总数" :count="indexData.movieCount">
            <Film/>
          </count-card>
        </div>
        <div class="card-padding-left">
          <count-card title="用户总数" :count="indexData.userCount">
            <User/>
          </count-card>
        </div>
        <div class="card-padding-left">
          <count-card title="在线用户" :count="0">
            <UserFilled />
          </count-card>
        </div>
        <div class="card-padding-left">
          <count-card title="已售电影票总数" :count="indexData.orderCount">
            <Ticket />
          </count-card>
        </div>
        <div class="card-padding-left">
          <count-card title="销售额" :count="parseFloat(indexData.salesVolume)">
            <Coin />
          </count-card>
        </div>
      </el-space>
      <div class="chart">
        <line-charts :data-list="chartsProps.dataList" :time-list="chartsProps.timeList"></line-charts>
      </div>
    </div>


  </div>
</template>

<style scoped>
.content{
  flex:1;
  display: flex;
}
.space{
  flex: 1;
  display: flex;
  flex-direction: column;
}
.card-space{
  flex:1;
}
.chart{
  flex: 5;
  background-color: #fdfdfd;
  border-radius: 10px;
}
.card-padding-left{
  padding-left: 30px;
}
</style>